// import { routerRedux } from 'dva/router';
import router from 'umi/router';
import { login } from '@/services/api'
import settings from '@/settings'

export default {
	namespace: 'login',
	state: {
	},
	reducers: {
		updateState(state, { payload }) {
			return {
				...state,
				...payload
			}
		}
	},
	effects: {
		*login({
			payload
		}, {
			put, call
		}) {
			const { code, message } = yield call(login, payload)
			// yield put(routerRedux.replace('/'));
			if (code === settings.code) {
				yield put({
					type: 'updateState',
					payload: {
						error: null
					}
				})
				router.push({
					pathname: '/task/week'
				})
			} else {
				yield put({
					type: 'updateState',
					payload: {
						error: {
							message
						}
					}
				})
			}
		}
	}
}